<?php  session_start();
	$user = $_REQUEST["user"];
	$pass = md5($_REQUEST["pass"]);
	$gid = 2;
	$gender = $_REQUEST["gioitinh"];
	$age = $_REQUEST["tuoi"];
	$diachi = $_REQUEST["diachi"];
	$email = $_REQUEST["mail"];	
	$status="null";
	$dienthoai = $_REQUEST["phone"];
	$ten = $_REQUEST["fullname"];

if($ten==null)
{
	echo "<script>window.location='index.php';</script>";
	mysql_close();
}
else
{	
	require("connect.php");
	$test = mysql_query("Select * from user where email = '{$email}'");
	$test2 = mysql_query("Select * from user where uname = '{$user}'");
	$a1 = mysql_num_rows($test);
	$a2 = mysql_num_rows($test2);
	if(mysql_num_rows($test)>0)
	{
		mysql_close();
		$_SESSION["loi_email"]="<font color='red'>Emai nay da co nguoi su dung! hay dung mot Email khac!</font>";
		echo "<script>window.location='register.php';</script>";		
	}
	else $_SESSION["loi_email"]=null;
	if(mysql_num_rows($test2)>0)
	{
		mysql_close();
				$_SESSION["loi_user"]="<font color='red'>Tai khoan nay da co nguoi su dung!hay dung mot tai khoan khac</font>";
		echo "<script>window.location='register.php';</script>";

	}
	else $_SESSION["loi_user"]=null;
	if($a1 <= 0 && $a2 <=0)
	{	
	
$sql = "Insert Into user (uname, upass, gid, gender,age,address,email,phone,status,fullname) Values 						           					('{$user}','{$pass}','{$gid}','{$gender}','{$age}','{$diachi}','{$email}','{$dienthoai}','{$status}' ,'{$ten}')";
		mysql_query($sql) or die ($sql);
		mysql_close();
				$_SESSION["loi_user"]=null;
		$_SESSION["loi_email"]=null;
		$_SESSION["user"]=$user;

		echo "<script>window.location='index.php';</script>";
	}
}
?>